﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using DAL;
using Common;


public partial class Stock_WxStock1 : System.Web.UI.Page
{
    protected string ParentID
    {
        get { return Request["ParentID"].ToString(); }
    }
    protected string ParentID1
    {
        get { return Request["ParentID1"].ToString(); }
    }
    
    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }

    protected int UserType;

    protected string DanNumClientID;

    protected void Page_PreRender(object sender, EventArgs e)
    {
            UserType = Convert.ToInt32(Session["UserType"]);
        
            OneDate.Attributes.Add("onclick","selectDate(this);");
            TwoDate.Attributes.Add("onclick", "selectDate(this);"); 

            //条件 Hashtable

            Hashtable tb = new Hashtable();
            bool QueryAdd = false;

            tb.Add("StockStatus", "已出库");
            QueryAdd = true;

            if (!string.IsNullOrEmpty(StName.Text.Trim()))
            {
                tb.Add("StockName", StName.Text.Trim());
                QueryAdd = true;
            }
            if (!string.IsNullOrEmpty(Keyword.Text.Trim()))
            {
                tb.Add("Keyword", Keyword.Text.Trim());
                QueryAdd = true;
            }
            if (OneDate.Text.Trim() != "选择开始日期")
            {
                tb.Add("OneDate", OneDate.Text.Trim());
                QueryAdd = true;
            }
            if (TwoDate.Text.Trim() != "选择结束日期")
            {
                tb.Add("TwoDate", TwoDate.Text.Trim());
                QueryAdd = true;
            }
            tb = QueryAdd ? tb : null;

            WxStockDataBind(tb);
    }

    private void WxStockDataBind(Hashtable QueryTable)
    {
        lv_WxStock.DataSource = new WxStock().SelectWxStock(QueryTable);
        lv_WxStock.DataBind();

        if (DataPager1.TotalRowCount == 0)
            DataPager1.Visible = false;
    }

    //搜索
    protected void submit_Click(object sender, EventArgs e)
    {
        Hashtable tb = new Hashtable();
        bool QueryAdd = false;

        //条件 Hashtable

        if (!string.IsNullOrEmpty(StName.Text.Trim()))
        {
            tb.Add("StName", StName.Text.Trim());
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(Keyword.Text.Trim()))
        {
            tb.Add("Keyword", Keyword.Text.Trim());
            QueryAdd = true;
        }
        if (OneDate.Text.Trim() != "选择开始日期")
        {
            tb.Add("OneDate", OneDate.Text.Trim());
            QueryAdd = true;
        }
        if (TwoDate.Text.Trim() != "选择结束日期")
        {
            tb.Add("TwoDate", TwoDate.Text.Trim());
            QueryAdd = true;
        }
        tb = QueryAdd ? tb : null;

        WxStockDataBind(tb);
    }

    protected void lv_WxStock_DataBound(object sender, EventArgs e)
    {
        DropDownList pagelist = (DropDownList)DataPager1.Controls[4].FindControl("PageList");

        int CurPage = WebUtility.GetCurrentPage(DataPager1.StartRowIndex, DataPager1.PageSize);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);
        for (int i = 1; i <= TotalPage; i++)
            pagelist.Items.Add(new ListItem("第" + i.ToString() + "页", i.ToString()));
        pagelist.SelectedValue = CurPage.ToString();
    }

    //DropDownList分页选择
    protected void PageList_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList pagelist = (DropDownList)sender;

        int CurPage = Convert.ToInt32(pagelist.SelectedValue);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);

        DataPager1.SetPageProperties((CurPage - 1) * DataPager1.PageSize, DataPager1.PageSize, true);
    }


    protected void lv_WxStock_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            new WxStock().DelWxStock(Convert.ToInt32(e.CommandArgument));
        }
    }

    protected string GetWxContent(string WxStatus,int WxStockKey)
    {   
        string Content = "";

        Dat_WxStock wxstock = new WxStock().SelectWxStock(WxStockKey);

        if ( WxStatus=="已修复" )
        {
            Content += "最终价格："+ wxstock.FinalPrice; 
        }
        else if (WxStatus=="更换")
        {
            Content += "更换物品："+ wxstock.ChangeStock + "<br>"; 
            Content += "销售价格："+ wxstock.SalePrice; 
        }
        else if (WxStatus == "未修复")
        {

        }
        return Content;
    }
}
